﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;
using ZWL.DBUtility;//请先添加引用
namespace ZWL.BLL
{
    /// <summary>
    /// 计划
    /// </summary>
   public  class Pro_Plan
    {
       public Pro_Plan() { }
       #region Model
       private int _id;
       private string _ProjectName;
       private string _PlanWenHao;
       private string _ProXingZhi;
       private string _ChengYuanDanWei;
       private float _PlanMoney;
       private string _ShiGongDanWei;
       private string _FenBaoHead;
       private string _MainContent;

       /// <summary>
       /// 
       /// </summary>
       public int ID
       {
           set { _id = value; }
           get { return _id; }
       }

       /// <summary>
       /// 工程名称
       /// </summary>
       public string ProjectName
       {
           set { _ProjectName = value; }
           get { return _ProjectName; }
       }
       /// <summary>
       /// 计划文号
       /// </summary>
       public string PlanWenHao
       {
           set { _PlanWenHao = value; }
           get { return _PlanWenHao; }
       }
       /// <summary>
       /// 工程性质
       /// </summary>
       public string ProXingZhi
       {
           set { _ProXingZhi = value; }
           get { return _ProXingZhi; }
       }
       /// <summary>
       /// 成员单位
       /// </summary>
       public string ChengYuanDanWei
       {
           set { _ChengYuanDanWei = value; }
           get { return _ChengYuanDanWei; }
       }
       /// <summary>
       /// 计划金额
       /// </summary>
       public float PlanMoney
       {
           set { _PlanMoney = value; }
           get { return _PlanMoney; }
       }
       /// <summary>
       /// 施工单位
       /// </summary>
       public string ShiGongDanWei
       {
           set { _ShiGongDanWei = value; }
           get { return _ShiGongDanWei; }
       }
       /// <summary>
       /// 分包负责人
       /// </summary>
       public string FenBaoHead
       {
           set { _FenBaoHead = value; }
           get { return _FenBaoHead; }
       }
       /// <summary>
       /// 主要内容
       /// </summary>
       public string MainContent
       {
           set { _MainContent = value; }
           get { return _MainContent; }
       }
     
       #endregion Model
    #region  成员方法

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pro_Plan(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,ProjectName,PlanWenHao,ProXingZhi,ChengYuanDanWei,PlanMoney,ShiGongDanWei,FenBaoHead,MainContent ");
            strSql.Append(" FROM Pro_Plan ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString() != "" ? ds.Tables[0].Rows[0]["ProjectName"].ToString() : "";
                PlanWenHao = ds.Tables[0].Rows[0]["PlanWenHao"].ToString() != "" ? ds.Tables[0].Rows[0]["PlanWenHao"].ToString() : "";
                ProXingZhi = ds.Tables[0].Rows[0]["ProXingZhi"].ToString() != "" ? ds.Tables[0].Rows[0]["ProXingZhi"].ToString() : "";
                ChengYuanDanWei = ds.Tables[0].Rows[0]["ChengYuanDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["ChengYuanDanWei"].ToString() : "";
                PlanMoney = ds.Tables[0].Rows[0]["PlanMoney"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["PlanMoney"].ToString()) : 0;
                ShiGongDanWei = ds.Tables[0].Rows[0]["ShiGongDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["ShiGongDanWei"].ToString() : "";
                FenBaoHead = ds.Tables[0].Rows[0]["FenBaoHead"].ToString() != "" ? ds.Tables[0].Rows[0]["FenBaoHead"].ToString() : "";
                MainContent = ds.Tables[0].Rows[0]["MainContent"].ToString() != "" ? ds.Tables[0].Rows[0]["MainContent"].ToString() : "";
         

            }
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("ID", "Pro_Plan");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Pro_Plan");
            strSql.Append(" where ID=@ID ");

            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Pro_Plan(");
            strSql.Append("ProjectName,PlanWenHao,ProXingZhi,ChengYuanDanWei,PlanMoney,ShiGongDanWei,FenBaoHead,MainContent)");
            strSql.Append(" values (");
            strSql.Append("@ProjectName,@PlanWenHao,@ProXingZhi,@ChengYuanDanWei,@PlanMoney,@ShiGongDanWei,@FenBaoHead,@MainContent)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@ProjectName", SqlDbType.VarChar,100),
					new SqlParameter("@PlanWenHao", SqlDbType.VarChar,50),
					new SqlParameter("@ProXingZhi", SqlDbType.VarChar,10),
					new SqlParameter("@ChengYuanDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@PlanMoney", SqlDbType.Float,10),
					new SqlParameter("@ShiGongDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@FenBaoHead", SqlDbType.VarChar,50),
					new SqlParameter("@MainContent", SqlDbType.VarChar,1000)};
            parameters[0].Value = ProjectName;
            parameters[1].Value = PlanWenHao;
            parameters[2].Value = ProXingZhi;
            parameters[3].Value = ChengYuanDanWei;
            parameters[4].Value = PlanMoney;
            parameters[5].Value = ShiGongDanWei;
            parameters[6].Value = FenBaoHead;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Pro_Plan set ");
            strSql.Append("ProjectName=@ProjectName,");
            strSql.Append("PlanWenHao=@PlanWenHao,");
            strSql.Append("ProXingZhi=@ProXingZhi,");
            strSql.Append("ChengYuanDanWei=@ChengYuanDanWei,");
            strSql.Append("PlanMoney=@PlanMoney,");
            strSql.Append("ShiGongDanWei=@ShiGongDanWei,");
            strSql.Append("FenBaoHead=@FenBaoHead,");
            strSql.Append("MainContent=@MainContent ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4),
					new SqlParameter("@ProjectName", SqlDbType.VarChar,100),
					new SqlParameter("@PlanWenHao", SqlDbType.VarChar,50),
					new SqlParameter("@ProXingZhi", SqlDbType.VarChar,10),
					new SqlParameter("@ChengYuanDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@PlanMoney", SqlDbType.Float,10),
					new SqlParameter("@ShiGongDanWei", SqlDbType.VarChar,50),
					new SqlParameter("@FenBaoHead", SqlDbType.VarChar,50),
					new SqlParameter("@MainContent", SqlDbType.VarChar,1000)};
            parameters[0].Value = ID;
            parameters[1].Value = ProjectName;
            parameters[2].Value = PlanWenHao;
            parameters[3].Value = ProXingZhi;
            parameters[4].Value = ChengYuanDanWei;
            parameters[5].Value = PlanMoney;
            parameters[6].Value = ShiGongDanWei;
            parameters[7].Value = FenBaoHead;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Pro_Plan ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,ProjectName,PlanWenHao,ProXingZhi,ChengYuanDanWei,PlanMoney,ShiGongDanWei,FenBaoHead,MainContent ");
            strSql.Append(" FROM Pro_Plan ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                ProjectName = ds.Tables[0].Rows[0]["ProjectName"].ToString() != "" ? ds.Tables[0].Rows[0]["ProjectName"].ToString() : "";
                PlanWenHao = ds.Tables[0].Rows[0]["PlanWenHao"].ToString() != "" ? ds.Tables[0].Rows[0]["PlanWenHao"].ToString() : "";
                ProXingZhi = ds.Tables[0].Rows[0]["ProXingZhi"].ToString() != "" ? ds.Tables[0].Rows[0]["ProXingZhi"].ToString() : "";
                ChengYuanDanWei = ds.Tables[0].Rows[0]["ChengYuanDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["ChengYuanDanWei"].ToString() : "";
                PlanMoney = ds.Tables[0].Rows[0]["PlanMoney"].ToString() != "" ? float.Parse(ds.Tables[0].Rows[0]["PlanMoney"].ToString()) : 0;
                ShiGongDanWei = ds.Tables[0].Rows[0]["ShiGongDanWei"].ToString() != "" ? ds.Tables[0].Rows[0]["ShiGongDanWei"].ToString() : "";
                FenBaoHead = ds.Tables[0].Rows[0]["FenBaoHead"].ToString() != "" ? ds.Tables[0].Rows[0]["FenBaoHead"].ToString() : "";
                MainContent = ds.Tables[0].Rows[0]["MainContent"].ToString() != "" ? ds.Tables[0].Rows[0]["MainContent"].ToString() : "";
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM Pro_Plan ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

       

        #endregion  成员方法


    }
}
